export const crudMxins = {
	data() {
		return {
			form: {},
			query: {},
			selectionList:[],
			loading: true,
			page: {
				pageSize: 10,
				currentPage: 1,
				total: 0
			},
			data: [],
			column: []
		}
	},
	computed: {
		option() {
			return {
				calcHeight: 30,
				searchShow: true,
				searchMenuSpan: 5,
				addBtn: false,
				editBtn: false,
				dialogClickModal: false,
				dialogDrag: true,
				tip: false,
				border: true,
				searchIndex: 10,
				searchIcon: true,
				span: 13,
				viewBtn: false,
				delBtn: false,
				menuWidth: 200,
				index: true,
				indexLabel: '序号',
				column: this.column
			};
		}
	},
	created() {

	},
	methods: {
		onLoad(page, params = {}) {
			this.loading = true
			getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
				const {
					list,
					rowCount
				} = res.data
				this.page.total = rowCount
				this.data = list
				this.loading = false
			})
		},
		searchReset() {
			this.query = {};
			this.$refs.crud.clearSort();
			this.onLoad(this.page);
		},
		searchChange(params, done) {
			this.query = params;
			this.page.currentPage = 1;
			this.onLoad(this.page, params);
			done();
		},

		currentChange(currentPage) {
			this.page.currentPage = currentPage;
		},
		sizeChange(pageSize) {
			this.page.pageSize = pageSize;
		},
		refreshChange() {
			this.page.currentPage = 1;
			this.onLoad(this.page, this.query);
		},
		selectionChange(list) {
			this.selectionList = list
		},
		selectionClear() {
			this.selectionList = []
			this.$refs.crud.toggleSelection()
		},
	}
};